import dayjs from "dayjs";

export default function formatTime(time) {
    const now = new Date();
    const givenTime = new Date(time);

    const seconds = Math.floor((now - givenTime) / 1000);
    const minutes = Math.floor(seconds / 60);
    const hours = Math.floor(minutes / 60);
    const days = Math.floor(hours / 24);

    if (days > 0) {
        return dayjs(givenTime).format('YYYY-MM-DD');
    } else if (hours > 0) {
        return `${hours}小时前`;
    } else if (minutes > 0) {
        return `${minutes}分钟前`;
    } else {
        return `刚刚`;
    }
}
